#-----Macros---------------------------------

BASEDIR = /home/adam/compiler/java2c++
TLIB = $(BASEDIR)
INCLUDES = -I. -I$(BASEDIR)

# set up compiler and options
CC = gcc
CCFLAGS = -g $(INCLUDES)
LEX = flex --yylineno
YACC = bison -t -v --report=all

#-----Suffix Rules---------------------------
# set up C suffixes and relationship between .c and .o files

default: all

lexical.o: parser.h lexical.l
	$(LEX) -o lexical.c lexical.l
	$(CC) $(CCFLAGS) -c lexical.c
	rm -f lexical.c

parser.h parser.o: parser.y parsetree.h
	rm -f parser.h
	$(YACC) -o parser.c --defines=parser.h parser.y
	$(CC) $(CCFLAGS) -c parser.c
	rm -f parser.c

.SUFFIXES: .c

.c.o:
	$(CC) $(CCFLAGS) -c $<

#-----File Dependencies----------------------

SRC = lexical.l parser.y parsetree.c

OBJ = $(addsuffix .o, $(basename $(SRC)))

all: java2c++

java2c++: $(OBJ)
	$(CC) $(CCFLAGS) -o $@ $(OBJ) 

#-----Other stuff----------------------------

clean:
	rm -f $(OBJ)
	rm -f parser.h
	rm -f java2c++
	rm -f *.output
	rm -f *.geany
